package it.unibo.refolding.pico.jpk;

import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

class ExtendPauseRetract {

    int[] extendIndex = {-1, -1};
    int[] pauseIndex = {-1, -1};
    int[] retractIndex = {-1, -1};

    boolean isEmpty() {
        return extendIndex[0] == -1 & retractIndex[0] == -1;
    }

    boolean isFinished() {
        return retractIndex[0] != -1;
    }

    @Override
    public String toString() {
        return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

    private int[] array(int index) {
        switch (index) {
        case 0:
            return extendIndex;
        case 1:
            return pauseIndex;
        case 2:
            return retractIndex;
        default:
            throw new IllegalArgumentException(Integer.toString(index));
        }
    }

    public boolean isAfter(ExtendPauseRetract other) {
        for (int i = 0; i < 3; ++i) {
            int[] a = array(i), b = other.array(i);
            for (int j = 0; j < 2; ++j) {
                if (!(a[j] == -1 | b[j] == -1 | a[j] > b[j])) {
                    return false;
                }
            }
        }
        return true;
    }
}
